<template>
  <div class="home">
    <button @click="login">登录</button>
    <!-- 演示遮罩方式 -->
    <div id="captcha-mask" v-show="showCaptchaMask">
      <div id="captcha-div"></div>
    </div>
  </div>
</template>

<script>

export default {
  name: 'HomeView',
  data() {
    return {
      showCaptchaMask: false
    }
  },
  methods: {
    login() {
      this.showCaptchaMask=true
      const captchaConfig = {
        // 请求验证码接口
        requestCaptchaDataUrl: "http://localhost:8083/gen",
        // 验证验证码接口
        validCaptchaUrl: "http://localhost:8083/check",
        // 绑定的div
        bindEl: "#captcha-div",
        // 验证成功回调函数
        validSuccess: (res, c, t) => {
          console.log("验证码验证成功回调...")
          // 销毁验证码
          t.destroyWindow();
          this.showCaptchaMask=false
          alert("验证成功,token:" + res.data.token)
          // todo 携带token调用业务登录方法
        },
        btnCloseFun:() => {
          this.showCaptchaMask=false
        }
      }

      window.initTAC("captcha/tac", captchaConfig).then(tac => {
       tac.init();
      })
    }
  }
}
</script>

<style>
#captcha-mask {
  display: flex;
  z-index: 99;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.53);
  justify-content: center;
  align-items: center;
}
</style>
